package org.particlethink.model;


import org.particlethink.entry.PlanStatus;
import org.particlethink.handler.PlanStatusHandler;
import tk.mybatis.mapper.annotation.ColumnType;
import tk.mybatis.mapper.annotation.KeySql;

import javax.persistence.Id;
import javax.persistence.Table;
import java.util.Date;

@Table(name = "master_plans")
public class MasterPlan {//总计划
    @Id
    @KeySql(useGeneratedKeys = true)
    private Integer id;
    private String no; //单号
    private Integer projectId;//项目ID
    private String masterPlanCategoryId;//总计划大类

    @ColumnType(typeHandler = PlanStatusHandler.class)
    private PlanStatus status;
    private String remark;//备注

    private Integer creatorId;//创建人
    private Date createdAt;//创建时间

    private Integer submitId;//提交人
    private Date submitAt;//提交时间
    private String attachment;//附件
    private String attachmentName;//附件
    //todo 更新批次计划数量
    private Integer batchPlanCount;//批次计划数量

    public MasterPlan() {
    }



    public MasterPlan(Integer projectId, String masterPlanCategoryId, String remark, Integer creatorId, String attachment, String attachmentName,String no) {
        this.projectId = projectId;
        this.no = no;
        this.masterPlanCategoryId = masterPlanCategoryId;
        this.remark = remark;
        this.creatorId = creatorId;
        this.attachment = attachment;
        this.attachmentName = attachmentName;
        this.status = PlanStatus.UnDisposed;
        this.createdAt = new Date();
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getId() {
        return id;
    }

    public void setCreatedAt(Date createdAt) {
        this.createdAt = createdAt;
    }

    public Date getCreatedAt() {
        return createdAt;
    }


    public void setProjectId(Integer projectId) {
        this.projectId = projectId;
    }

    public Integer getProjectId() {
        return projectId;
    }

    public void setMasterPlanCategoryId(String masterPlanCategoryId) {
        this.masterPlanCategoryId = masterPlanCategoryId;
    }

    public String getMasterPlanCategoryId() {
        return masterPlanCategoryId;
    }

    public void setStatus(PlanStatus status) {
        this.status = status;
    }

    public PlanStatus getStatus() {
        return status;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public String getRemark() {
        return remark;
    }

    public void setCreatorId(Integer creatorId) {
        this.creatorId = creatorId;
    }

    public Integer getCreatorId() {
        return creatorId;
    }

    public void setSubmitId(Integer submitId) {
        this.submitId = submitId;
    }

    public Integer getSubmitId() {
        return submitId;
    }

    public void setSubmitAt(Date submitAt) {
        this.submitAt = submitAt;
    }

    public Date getSubmitAt() {
        return submitAt;
    }

    public void setAttachment(String attachment) {
        this.attachment = attachment;
    }

    public String getAttachment() {
        return attachment;
    }


    public boolean canDelete() {
        return status.IsUnDisposed();
    }

    public boolean canSubmit() {
        return status.IsUnDisposed();
    }

    public boolean canEnable() {
        return status.IsDiscarded();
    }


    public boolean canEdit() {
        return status.IsSubmitted() || status.IsUnDisposed();//未提交保存为草稿就是修改
    }


    public boolean canDiscard() {
        return status.IsSubmitted();
    }

    public boolean canCreateBatchPlan() {
        return status.IsSubmitted();
    }


    public Integer getBatchPlanCount() {
        return batchPlanCount == null ? 0 : batchPlanCount;
    }

    public void setBatchPlanCount(Integer batchPlanCount) {
        this.batchPlanCount = batchPlanCount;
    }


    public String getNo() {
        return no;
    }

    public void setNo(String no) {
        this.no = no;
    }

    public String getAttachmentName() {
        return attachmentName;
    }

    public void setAttachmentName(String attachmentName) {
        this.attachmentName = attachmentName;
    }
}


